/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package panel;

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import utils.Debug;

/**
 *
 * @author daz
 */
public class TabPanel {

    JFrame frame;
    private static final String BUILD_FILE = "Build File";
    private static final String ADD_CP = "Thêm/Sửa Cp";
    private static final String DB_INFO = "Thông tin database";
    private static final String USER_INFO = "Thông tin user";
    private static final String CP_INFO = "Thông tin cp";
    private static final String STATISTIC_INFO = "Thống kê";
    private static final String BUILD_MANY_FILE = "Build hàng loạt";
    private BuildFilePanel buildFilePanel;
    private BuildManyFilePanel buildManyFilePanel;

    public TabPanel(JFrame frame) {
        this.frame = frame;
    }

    public void addComponentToPane(Container pane) {
        //init
        JTabbedPane tabbedPane = new JTabbedPane();
        buildFilePanel = new BuildFilePanel(frame);
        DatabaseInfoPanel databaseInfoPanel = new DatabaseInfoPanel(frame);
        AddCpPanel addCpPanel = new AddCpPanel(frame);
        UserInfoPanel userInfoPanel = new UserInfoPanel(frame);
        CpInfoPanel cpInfoPanel = new CpInfoPanel(frame);
        StatisticPanel statisticPanel = new StatisticPanel(frame);
        buildManyFilePanel = new BuildManyFilePanel(frame);
        //add tab
        tabbedPane.addTab(BUILD_FILE, buildFilePanel);
        tabbedPane.addTab(ADD_CP, addCpPanel);
        tabbedPane.addTab(USER_INFO, userInfoPanel);
        tabbedPane.addTab(CP_INFO, cpInfoPanel);
        tabbedPane.addTab(STATISTIC_INFO, statisticPanel);
        tabbedPane.addTab(DB_INFO, databaseInfoPanel);
        tabbedPane.addTab(BUILD_MANY_FILE, buildManyFilePanel);
        pane.add(tabbedPane, BorderLayout.CENTER);
        tabbedPane.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent evt) {
                JTabbedPane jTabbedPane = (JTabbedPane) evt.getSource();
                // Get current tab
                int sel = jTabbedPane.getSelectedIndex();
                Debug.d(sel + "focus :" + jTabbedPane.getTitleAt(sel));
                if (sel == 0) {
                    buildFilePanel.setCpList();
                } else if (sel == 6) {
                    buildManyFilePanel.setCpList();
                }
            }
        });
    }
}
